package com.ttdev.mmms.repository;

import com.ttdev.mmms.entity.Account;
import com.ttdev.mmms.entity.MemberInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Coca-Cola
 * @sketch 会员信息维护管理Repository
 * @date 2019/12/2 14:49
 */
@Repository
public interface MemberRepository {

    // 查询会员
    @Select("select * from member_info where store_id = #{storeId}")
    public List<MemberInfo> findsAll(Integer storeId);


    // 根据卡号查会员信息
    @Select("select * from member_info where card_id=#{cardId}")
    public List<MemberInfo> queryMember(Integer cardId);

    // 根据用户名查询会员信息
    @Select("select * from member_info where name=#{username}")
    public MemberInfo findPwd(String username);

    //添加会员
    @Insert("insert into member_info(card_id,store_id,iphone,name,password,birthday,balance,type,state,integral,time) value(#{cardId},#{storeId},#{iphone},#{name},#{password},#{birthday},#{balance},#{type},#{state},#{integral},#{time})")
    public int add(MemberInfo member);

    //修改会员
    @Update("update member_info set iphone=#{iphone},name=#{name},birthday=#{birthday},state=#{state} where card_id=#{cardId}")
    public int update(MemberInfo member);

    //根据卡号删除会员
    @Delete("delete from member_info where card_id=#{cardId}")
    public int delete(Integer cardId);

    // 根据用户名查询用户
    @Select("select card_id from member_info where name=#{user}")
    public Integer selectMemberName(String user);

    // 根据用户名查询用户
    @Select("select name from member_info where iphone=#{iphone}")
    public MemberInfo selectMemberIphone(Integer iphone);

    //根据卡号或者手机号查询
    @Select("select * from member_info where card_id = #{card_id} OR iphone = #{iphone}")
    public List<MemberInfo> query(Integer card_id,String iphone);

    //根据卡号更改余额
    @Update("update member_info set balance = balance + #{balance} where card_id = #{cardId}")
    public int updateBalance(Double balance,Integer cardId);

    // 用户扣款
    @Update("update member_info set balance = balance - #{price} where card_id = #{card}")
    public int payment(Integer card,Double price);

    // 入账
    @Insert("insert into account_info(card_id,store_id,money,type) value(#{cardId},#{sId},#{money},#{type})")
    public int account(int cardId,int sId,double money,String type);

    //根据卡号更改密码
    @Update("update member_info set password = #{newPassword} where card_id = #{card_id}")
    public int updatePassword(String newPassword,Integer card_id);


}
